﻿using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Ghasam.Business.Services;
using Ghasam.Business.Services.Impl;
using System.Collections.Generic;
using Ghasam.Business.Domain.Entity;
using Spring.Context;


[WebService(Namespace = "http://crm.ghasam.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : System.Web.Services.WebService {


    public ISalesPersonService SalesPersonService {
        get {
            IApplicationContext context = Spring.Context.Support.ContextRegistry.GetContext();
            return (ISalesPersonService)context.GetObject("SalesPersonService");
        }

    }

    public IInternalAccountingService InternalAccountingService {
        get {
            IApplicationContext context = Spring.Context.Support.ContextRegistry.GetContext();
            return (IInternalAccountingService)context.GetObject("InternalAccountingService");
        }
    }

    public AutoCompleteService() {
    }

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetSalesPersonName( string prefixText, int count ) {
        IList<SalesPerson> salesPersons = SalesPersonService.FindByTitleLike(prefixText);
        string[] titles = new string[salesPersons.Count];

        for (int i = 0; i < salesPersons.Count; i++) {
            titles[i] = salesPersons[i].Title;
        }

        return titles;
    }

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetItemName(string prefixText, int count) {
        IList<Item> items = InternalAccountingService.FindItemByNameLike(prefixText);
        string[] names = new string[items.Count];

        for (int i = 0; i < items.Count; i++) {
            names[i] = items[i].Name;
        }

        return names;
    }

}

